﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<!--/* 加载IE8兼容性片段 */-->
<head>
    <title>数据源管理</title>
    <!--/* 加载全局样式 */-->
    <th:block th:replace="common/thinDecorator::globalStyle"></th:block>
    <!--/* 加载全局主题样式 */-->
    <th:block th:replace="common/thinDecorator::globalThemeStyle"></th:block>
    <!--/* 加载全局布局样式 */-->
    <th:block th:replace="common/thinDecorator::globalLayoutStyle"></th:block>
</head>

<body class="page-content-white page-container-bg-solid" style="overflow-x: hidden;">
<div class="page-wrapper">
    <!-- BEGIN CONTAINER -->
    <div class="page-container">
        <!-- BEGIN CONTENT -->
        <div class="page-content-wrapper">
            <!-- BEGIN CONTENT BODY -->
            <div class="page-content">
                <div class="row">
                    <div class="col-md-12">
                        <div class="portlet light" style="margin-bottom: 0px;">
                            <div class="portlet-title">
                                <button type="button" class="btn btn-success " onclick="javascript:App.search();">
                                    搜索
                                </button>
                                <button type="button" class="btn btn-success" style="margin-left: 5px"
                                        onclick="javascript:App.reset();">
                                    重置
                                </button>
                                <button type="button" class="btn btn-success" style="margin-left: 5px"
                                        onclick="javascript:window.location.href='/qa/biaozhun/detail'">新增标准
                                </button>
                                <button type="button" class="btn btn-success" style="margin-left: 5px"
                                        onclick="javascript:dataList.updateInfo()">修改标准
                                </button>
                                <button type="button" class="btn btn-success" style="margin-left: 5px"
                                        onclick="javascript:dataList.removeSelect()">删除
                                </button>
                                <button type="button" class="btn btn-success" style="margin-left: 5px"
                                        onclick="javascript:dataList.updateState(1)">提交发布
                                </button>
                                <button type="button" class="btn btn-success" style="margin-left: 5px"
                                        onclick="javascript:dataList.updateState(2)">取消发布
                                </button>
                                <button type="button" class="btn btn-success" style="margin-left: 5px"
                                        id="fileUpload">导入
                                </button>
                                <button type="button" class="btn btn-success" style="margin-left: 5px"
                                        onclick="javascript:dataList.exportExcel()">导出
                                </button>

                            </div>
                            <div class="portlet-body">
                                <table id="table" style="width:100%;"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- END CONTENT BODY -->
        </div>
        <!-- END CONTENT -->
    </div>
</div>
<div id="scripts">
    <!--/* 加载IE8兼容性脚本 */-->
    <th:block th:replace="common/thinDecorator::IE8FixScripts"/>
    <!--/* 加载核心插件脚本 */-->
    <th:block th:replace="common/thinDecorator::corePluginsScripts"/>
    <!--/* 加载全局主题脚本 */-->
    <th:block th:replace="common/thinDecorator::globalThemeScripts"/>
    <!--/* 加载全局布局脚本 */-->
    <th:block th:replace="common/thinDecorator::globalLayoutScripts"/>
    <th:block th:replace="common/thinDecorator::globalsetupScripts"/>
    <!--Axios请求-->
    <script th:src="@{/Vue/axios.min.js}" type="text/javascript" charset="utf-8"></script>
    <script th:inline="javascript">
        layui.use(['upload','layer'], function () {
            var upload = layui.upload;
            var layer = layui.layer;
            // 附件上传执行实例--单文件
            var uploadInst = upload.render({
                elem: '#fileUpload' //绑定元素
                , url: '/qa/excelSaveDb' //上传接口
                , multiple: false
                , exts: 'xls|xlsx'
                , number:1
                , accept: 'file' // 接受所有类型文件
                , done: function (res) {
                    //每个文件提交一次触发一次。“成功的回调”
                    layer.msg(res.msg, {icon: 1, time: 1000});
                    $("#table").datagrid("reload");
                }, error: function (err) {
                    //请求异常回调
                    console.log(err)
                }
            });
        });
        $(function () {
            dataList.init();
        });
        var dataList = {
            easyuiTableInput: {},//记录查询框输入值
            //初始化
            init: function () {
                this.easyuiTableInput = localStorageManage.get("table", "searchForm");
                if (!this.easyuiTableInput) {
                    this.easyuiTableInput = {
                        searchData: {},
                        queryParams: {},
                    };
                } else {
                    //写form表单查询
                }
                var height = App.countHeight("table");
                console.log("height is " + height)
                this.createDataGrid();
            },
            updateInfo: function () {
                var row = $("#table").datagrid("getSelections");
                if (row.length != 1) {
                    layer.msg("请有且选择一行数据编辑", {icon: 2, time: 1000, shift: 6});
                    return false;
                }
                window.location.href = "/qa/biaozhun/detail?id=" + row[0].id;
            },
            exportExcel:function (){
                var rows = $("#table").datagrid("getSelections");
                if (rows.length < 1) {
                    layer.msg("至少选择一行数据导出", {icon: 2, time: 1000, shift: 6});
                    return false;
                }
                let sendData = [];
                rows.forEach((item, index)=>{
                    sendData.push({
                        'id': item.id,
                        'cnName': item.cnName,
                        'syfw': item.syfw,
                        'sjzllx': item.sjzllx,
                        'ckwx': item.ckwx,
                        'sjzlbzml': item.sjzlbzml,
                        'fbzt': item.fbzt
                    })
                });
                axios({
                    method: "post",
                    url: "/qa/exportExcel",
                    data: sendData,
                    responseType: 'blob'
                }).then(resp => {
                    // 这里 data 是返回来的二进制数据
                    var blob = new Blob([resp.data]);
                    // 创建一个blob的对象链接
                    const url = window.URL.createObjectURL(blob);
                    const link = document.createElement('a');
                    link.href = url;
                    // 把获得的blob的对象链接赋值给新创建的这个 a 链接
                    link.setAttribute('download', '数据质量标准.xlsx'); // 设置下载文件名
                    document.body.appendChild(link);
                    // 使用js点击这个链接
                    link.click();
                    document.body.removeChild(link) // 下载完成移除元素
                    window.URL.revokeObjectURL(url) // 释放blob对象

                }).catch(error => {
                    console.log(error)
                });

            },
            removeSelect: function () {
                var rows = $("#table").datagrid("getSelections");
                if (rows.length < 1) {
                    layer.msg("请至少选择一行数据", {icon: 2, time: 1000, shift: 6});
                    return false;
                }
                let ids = '';
                rows.forEach((item, index) => {
                    ids += item.id + ",";
                });
                $.ajax({
                    url: "/qa/biaozhun/remove?ids=" + ids,
                    contentType: "application/json;charset=utf8",
                    data: {},
                    type: "post",
                    dataType: "json",
                    headers: {
                        'Content-Type': 'application/json;charset=utf8'
                    },
                    success: function (result) {
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000, shift: 6}, function () {
                                $("#table").datagrid("reload");
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 2000, shift: 6});
                        }
                    },
                    error: function (error) {
                        console.log(error)
                    }
                });
            },
            updateState: function (num) {
                // 发布
                var row = $("#table").datagrid("getSelections");
                if (row.length !== 1) {
                    layer.msg("请选择一行数据", {icon: 2, time: 1000, shift: 6});
                    return false;
                }
                let sendData = row[0];
                let msgLayer = "";
                let operation = "";
                if (num === 1) {
                    msgLayer = "确定发布";
                    operation = "FBZ";
                }else {
                    msgLayer = "确定取消发布";
                    operation = "WFB";
                }
                layer.confirm(msgLayer + row[0].cnName + "吗？", {
                        title: '发布操作',
                        icon: 3,
                        area: ['340px', '160px'], //弹框的大小
                        btn: ['确定', '取消'] //按钮
                    }, function (index) {
                        //  发布数据
                        axios.post("/qa/biaozhun/modifyStatus?operation="+operation, JSON.stringify(sendData), {
                            headers: {
                                'Content-Type': 'application/json'
                            }
                        }).then(resp => {
                            if (resp.data.code == 200) {
                                layer.msg(resp.data.msg, {icon: 1, time: 1000, shift: 6}, function () {
                                    $("#table").datagrid("reload");
                                });
                            } else {
                                layer.msg(resp.data.msg, {icon: 2, time: 1000, shift: 6});
                            }

                        }).catch(error => {
                            console.log(error)
                        });

                    }, function () {
                        //点击“取消”执行的操作
                        layer.close();
                    }
                )
                return true;
            },
            deleteByInfo: function () {
                var row = $("#table").datagrid("getSelections");
                if (row.length < 1) {
                    layer.msg("请至少选择一行数据", {icon: 2, time: 1000, shift: 6});
                    return false;
                }
                layer.confirm('确定删除吗？', {
                        title: '删除操作',
                        icon: 3,
                        area: ['340px', '160px'], //弹框的大小
                        btn: ['确定', '取消'] //按钮
                    }, function (index) {
                        //点击“确定”执行的操作
                        var ids = [];
                        for (var i = 0; i < row.length; i++) {
                            ids.push(row[i].id);
                        }
                        $.ajax({
                            url: "/qa/datasource/remove",
                            type: "post",
                            data: {
                                ids: ids.join(",")
                            }
                        }, function (result) {
                            layer.msg(result.msg, {icon: 1, time: 1000, shift: 6});
                        }, "json");
                        layer.close(index);
                        $("#table").datagrid("reload");
                    }, function () {
                        //点击“取消”执行的操作
                        layer.close();
                    }
                )
            },
            createDataGrid: function () {
                $("#table").datagrid({
                    url: "/qa/biaozhun/datagrid?sjzlbzml="+[[${BiaoZunMuID}]],
                    height: App.getPortletInnerHeight(),
                    queryParams: this.easyuiTableInput.queryParams,
                    frozenColumns: [
                        [
                            {field: 'checkbox', checkbox: true, align: "center", width: 35,},
                            {
                                field: 'number',
                                title: '序号',
                                align: "center",
                                width: 35,
                                formatter: function (data, row, index) {
                                    return index + 1;
                                }
                            },
                        ]
                    ],
                    columns: [
                        [

                            {
                                "field": "cnName", title: "数据质量名称", width: 140, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "syfw", title: "适用范围", width: 120, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "sjzllx", title: "数据质量类型", width: 140, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "createUser", title: "创建人", width: 120, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "createTime", title: "创建时间", width: 120, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "ckwx", title: "参考文献", width: 140, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "sjzlbzml", title: "数据质量标准目录", width: 120, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "fbzt", title: "发布状态", width: 100, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            }
                        ]
                    ],
                    fitColumns: false,//自适应
                    remoteFilter: true,
                    remoteSort: true,
                    clientPaging: false,
                    singleSelect: false,//单选
                    checkOnSelect: true,
                    striped: true, //表格设置为条纹
                    emptyMsg: "表中数据为空",
                    pagination: true,//分页
                    pagePosition: "bottom",
                    pageList: [20, 50, 100],
                    pageSize: 20,
                    automaticPolling: false,
                    onDblClickRow: function (rowIndex, row) {
                    }
                });
                this.createFilter();
            },
            //模糊查询
            createFilter: function () {
                $('#table').datagrid('enableFilter', [
                    {"field": "number", type: 'label',},
                    {
                        "field": "cnName", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.cnName,
                        }
                    },
                    {
                        "field": "syfw", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.syfw,
                        }
                    },
                    {
                        "field": "sjzllx", type: 'combobox', options: {
                            valueField: 'code',
                            textField: 'name',
                            editable: false,
                            data: [{code: '数据模型标准', name: '数据模型标准'}, {
                                code: '数据编码标准',
                                name: '数据编码标准'
                            }, {code: '主数据接口标准', name: '主数据接口标准'}],
                            value: dataList.easyuiTableInput.searchData.sjzllx,
                        }
                    },
                    {
                        "field": "createUser", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.createUser,
                        }
                    },
                    {
                        "field": "createTime", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.createTime,
                        }
                    },
                    {
                        "field": "ckwx", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.ckwx,
                        }
                    },
                    {
                        "field": "sjzlbzml", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.sjzlbzml,
                        }
                    },
                    {
                        "field": "fbzt", type: 'combobox', options: {
                            valueField: 'code',
                            textField: 'name',
                            editable: false,
                            data: [{code: '已发布', name: '已发布'}, {code: '未发布', name: '未发布'}, {
                                code: '发布中',
                                name: '发布中'
                            },{code: '已驳回', name: '已驳回'}],
                            value: dataList.easyuiTableInput.searchData.fbzt,
                        }
                    },
                ]);
                var searchBtn = '<a class="table-action" style="margin-left: 1px" onclick="App.search()">查询</a>';
                $('.datagrid-filter-row td[field="number"]').html(searchBtn);
            },
            edit: function () {
                var row = $("#table").datagrid("getSelected");
                if (0 !== row.stateId) {
                    layer.msg("该数据无法编辑", {icon: 2, time: 1000, shift: 6});
                    return false;
                }
                layer.msg("该数据无法编辑", {icon: 2, time: 1000, shift: 6});
            },
            back: function () {
                layer.msg("该数据无法编辑", {icon: 2, time: 1000, shift: 6});
            },
        };
    </script>
</div>
<!-- END CONTAINER -->
</body>

</html>